project('pacman', 'c')

sources = [
    'src/frontend/main.c',
    'src/frontend/dynstring.c',
    'src/frontend/renderer.c',
    'src/frontend/audio.c',
    'src/frontend/sokol_impl.c',

    'src/pacman/data.c',
    'src/pacman/interface.c',
    'src/pacman/render_util.c',
    'src/pacman/game.c',
    'src/pacman/sound.c',
    'src/pacman/player.c',
    'src/pacman/ghost.c',
    'src/pacman/ghost_ai.c',
    'src/pacman/maze_csv.c',
]
incdirs = []
dependencies = []

incdirs += include_directories('sokol')

if get_option('gfx_backend') == 'auto'
    if target_machine.system() == 'windows'
        gfx_backend = 'd3d11'
    elif target_machine.system() == 'darwin'
        gfx_backend = 'metal'
    else
        gfx_backend = 'glcore'
    endif
else
    gfx_backend = get_option('gfx_backend')
endif

c_args = []

cc = meson.get_compiler('c')

if gfx_backend == 'd3d11'
    c_args += ['-DSOKOL_D3D11']
    # sokol_gfx/d3d11 dependencies
    dependencies += cc.find_library('shell32')
    dependencies += cc.find_library('gdi32')
    dependencies += cc.find_library('dxgi')
    dependencies += cc.find_library('d3d11')
    dependencies += cc.find_library('ole32')
elif gfx_backend == 'glcore'
    c_args += ['-DSOKOL_GLCORE']
elif gfx_backend == 'metal'
    c_args += ['-DSOKOL_METAL']
else
    error('invalid option for gfx_backend')
endif

win_subsystem = 'console'
if get_option('buildtype') == 'release'
    win_subsystem = 'windows'
endif

executable('pacman', sources,
    win_subsystem : win_subsystem,
    include_directories : incdirs,
    dependencies : dependencies,
    c_args : c_args
)